package cn.edu.leetcode.二叉树;

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 * int val;
 * TreeNode left;
 * TreeNode right;
 * TreeNode() {}
 * TreeNode(int val) { this.val = val; }
 * TreeNode(int val, TreeNode left, TreeNode right) {
 * this.val = val;
 * this.left = left;
 * this.right = right;
 * }
 * }
 */

public class 翻转二叉树 {

    public static TreeNode invertTree(TreeNode root) {
        if (root == null) return null;
        TreeNode right = invertTree(root.left);
        TreeNode left = invertTree(root.right);
        root.right = right;
        root.left = left;

        return root;
    }

    public static void main(String[] args) {
        TreeNode treeNode = TreeNode.of(new int[]{1,2,3,4,5,6,7,8});
        treeNode = invertTree(treeNode);
        treeNode.show();
    }
}
